import QtQuick 2.6
import Qt.labs.controls 1.0
import QtQuick.Layouts 1.1
import QtQuick.XmlListModel 2.0
import "../template" as Template
import "../js/RecordBookedPage.qml.js" as Jrb
Template.Navigator {
    id: nav
    title: "签到"

    ColumnLayout {
        anchors.fill: parent
        anchors.margins: 9
        ListView {
            id: listView
            Layout.fillHeight: true
            Layout.fillWidth: true
            clip: true
            model: XmlListModel {
                id: xmlModel
                source: http.build("/sign.xml?t=s", {id:usinfo.id})
                query: "/signs/sign"

                XmlRole { name: "id"; query: "id/string()" }
                XmlRole { name: "date"; query: "date/string()" }
                XmlRole { name: "tm1"; query: "tm1/string()" }
                XmlRole { name: "tm2"; query: "tm2/string()" }
                XmlRole { name: "description"; query: "description/string()" }

                XmlRole { name: "placeid"; query: "place/id/string()" }
                XmlRole { name: "placename"; query: "place/display/string()" }
                XmlRole { name: "courseid"; query: "course/id/string()" }
                XmlRole { name: "coursename"; query: "course/display/string()" }
            }

            delegate: ItemDelegate {
                id: delegate
                width: listView.width
                height: implicitHeight * 4.5

                RowLayout {
                    anchors.fill: parent
                    anchors.margins: 9
                    Image {
                        Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
                        Layout.preferredWidth:100
                        Layout.preferredHeight: 100
                        source:  usinfo.image
                        onStatusChanged: {
                            if (status == Image.Null || status == Image.Error)  {
                                source ="../images/image_header.png"
                            }
                        }
                    }
                    ColumnLayout {
                        Layout.fillHeight: true
                        Layout.fillWidth: true

                        Layout.alignment: Qt.AlignLeft
                        spacing: 6

                        Label {
                            text: "日期：" + date
                        }

                        Label {
                            text: "起始时间：" + tm1
                        }
                        Label {
                            text: "终止时间：" + tm2
                        }
                        Label {
                            text: "场地：" + placename
                        }
                        Label {
                            text: "课程：" + coursename
                        }
                        Label {
                            text: "说明：" + description
                        }
                    }
                }
                Rectangle {
                    color: "forestgreen"
                    width: parent.width
                    height: 1
                    anchors.bottom: parent.bottom
                    visible: index != listView.count - 1
                }

            }
        }

        RecordSignPop {
            id: rspage
            onCallback: Jrb.add(date, time1, time2, course, place, description)
        }

        Button {
            text: "我要签到"
            Layout.alignment: Qt.AlignHCenter
            Layout.preferredWidth: implicitWidth * 2
            onClicked: rspage.open()
        }
    }
}
